import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * 
 */

/**
 * @author Nguyen Minh Tan
 *
 */
public class UsingTextBox extends MIDlet implements CommandListener {
	private TextBox textBox;
	private Command exitCommand;
	private Command playCommand;
	private Ticker ticker;
	
	public UsingTextBox(){
		textBox = new TextBox("Text Box Test",null,50,0);
		exitCommand = new Command("Exit",Command.EXIT,1);
		playCommand = new Command("Play",Command.OK,2);
		textBox.addCommand(exitCommand);
		textBox.addCommand(playCommand);
		textBox.setCommandListener(this);
	}
	/* (non-Javadoc)
	 * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
	 */
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.microedition.midlet.MIDlet#pauseApp()
	 */
	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.microedition.midlet.MIDlet#startApp()
	 */
	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		Display.getDisplay(this).setCurrent(textBox);
	}
	public void commandAction(Command command, Displayable arg1) {
		// TODO Auto-generated method stub
		if(command == exitCommand){
			notifyDestroyed();
		}
		if(command == playCommand){
			ticker = new Ticker("Hello " + textBox.getString() + " ^^!");
			textBox.setTicker(ticker);
		}
	}

}
